package com.io;

import java.io.File;
import java.io.FileFilter;

public class FileUtil {

    public static void print(String path) {

        File srcFile = new File(path);
        if (!srcFile.exists()) {
            System.out.println("路径不正确");
        }

        if (srcFile.isFile()) {
            String absolutePath = srcFile.getAbsolutePath();
            System.out.println("absolutePath = " + absolutePath);
        } else {
            File[] files = srcFile.listFiles();
            if (files != null) {
                for (File file : files) {
                    print(file.getAbsolutePath());
                }
            }
        }
    }

    public static void print(String path, String fileSuffix) {

        File srcFile = new File(path);
        if (!srcFile.exists()) {
            System.out.println("路径不正确");
        }

        if (srcFile.isFile() && srcFile.getName().endsWith(fileSuffix)) {
            String absolutePath = srcFile.getAbsolutePath();
            System.out.println("absolutePath = " + absolutePath);
        }
        File[] files = srcFile.listFiles((f)->{
            if(f.isDirectory())
                return true;
            return f.getName().endsWith(fileSuffix);
        });
        if (files != null) {
            for (File file : files) {
                print(file.getAbsolutePath(),fileSuffix);
            }
        }
    }
}
